package com.huage_07.lesson_04;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Comparator;
import java.util.TreeSet;

public class TreeSetToTxt {
    public static void main(String[] args) throws IOException {
        TreeSet<Student> tSet = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student s1, Student s2) {
                int num1 = s1.getChinese()- s2.getChinese();
                int num2 = num1==0?(s1.getMath()- s2.getMath()):num1;
                int num3 = num2==0?(s1.getArt()- s2.getArt()):num2;
                return num3;
            }
        });

        Student std1 = new Student("张三",96,97,94);
        Student std2 = new Student("李四",96,98,94);
        Student std3 = new Student("王五",96,98,97);

        tSet.add(std1);
        tSet.add(std2);
        tSet.add(std3);

        BufferedWriter bw = new BufferedWriter(new FileWriter("class1\\src\\com\\huage_07\\lesson_04\\学生成绩.txt"));

        for (Student std :tSet){
            bw.write(std.getName()+"  "+std.getChinese()+"   "+std.getMath()+"   "+std.getArt());
            bw.newLine();
            bw.flush();
        }

        bw.close();
    }
}
